package com.gw.booking.util;

import org.apache.commons.configuration.Configuration;
import org.apache.commons.configuration.ConfigurationException;
import org.apache.commons.configuration.PropertiesConfiguration;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class UtilProperties {
	private static final Logger logger = LoggerFactory.getLogger(UtilProperties.class);

	private static Configuration sftpConfig = null;
	private static Configuration aocConfig = null;
	private static Configuration esConfig = null;
	private static Configuration sizeConfig = null;
	private static Configuration nikebuyConfig = null;

	public static String getPropertyAsString(String resource, String name) {
		Configuration config = null;
		try {
			if (resource.equals("aoc-config.properties")) {
				if (aocConfig == null) {
					aocConfig = new PropertiesConfiguration("properties/" + resource);
				}
				config = aocConfig;
			} else if (resource.equals("elasticsearch.properties")) {
				if (esConfig == null) {
					esConfig = new PropertiesConfiguration("properties/" + resource);
				}
				config = esConfig;
			} else if (resource.equals("sftp.properties")) {
				if (sftpConfig == null) {
					sftpConfig = new PropertiesConfiguration("properties/" + resource);
				}
				config = sftpConfig;
			} else if (resource.equals("nikebuy.properties")) {
				if (nikebuyConfig == null) {
					nikebuyConfig = new PropertiesConfiguration("properties/" + resource);
				}
				config = nikebuyConfig;
			} else if (resource.equals("size.properties")) {
				if (sizeConfig == null) {
					sizeConfig = new PropertiesConfiguration("properties/" + resource);
				}
				config = sizeConfig;
			} else if (resource.equals("call-off.properties")) {
				if (sizeConfig == null) {
					sizeConfig = new PropertiesConfiguration("properties/" + resource);
				}
				config = sizeConfig;
			}
		} catch (ConfigurationException e) {
			throw new RuntimeException("get properties error");
		}

		return config.getString(name);
	}
}
